import login from '../utils/public.js'
let oParams = {}
location.search
  .slice(1)
  .split('&')
  .forEach((item) => {
    let _arr = item.split('=')
    let k = _arr[0]
    oParams[k] = _arr[1]
  })

const vm = new Vue({
  el: '#mybox',
  data() {
    return {
      question_day: 0,
      dialogVisible: false,
      userInfo: {
        amount: 0,
        question_all_times: 0,
        question_end_time: null,
        question_leave_times: 0,
      },
      loading: true,
    }
  },
  created() {
    login()
      .then((res) => {
        this.userInfo = res
        this.loading = false
        this.getDay(
          this.userInfo.question_end_time
            ? this.userInfo.question_end_time
            : null
        )
      })
      .catch((res) => {
        console.log(res)
      })
  },
  mounted() {},
  methods: {
    rechargeFn(hash) {
      window.location.href = './payment.html?openid=' + oParams.openid
    },
    rechargeListFn() {
      window.location.href = './rechargeList.html?openid=' + oParams.openid
    },
    getDay(date) {
      if (!date) return
      // 获取给定日期的时间戳
      var givenDate = new Date(date).getTime()

      // 获取今天的时间戳
      var today = new Date().getTime()

      // 计算日期差值（单位：毫秒）
      var difference = givenDate - today

      // 将毫秒转换为天数
      var daysRemaining = Math.ceil(difference / (1000 * 60 * 60 * 24))

      this.question_day = daysRemaining
    },
  },
})
